#ifndef DATABASE_H
#define DATABASE_H

#include <QObject>
#include <QtSql>

struct Part {
    QString part_id;
    QString name;
    QString description;
    double weight;
    QString supplier;
    QString status;
    QDateTime created_at;
    QDateTime updated_at;
};

struct Component {
    QString component_id;
    QString name;
    QString description;
    QDateTime created_at;
    QDateTime updated_at;
};

struct System {
    QString system_id;
    QString name;
    QString description;
    QDateTime created_at;
    QDateTime updated_at;
};

struct Product {
    QString product_id;
    QString name;
    QString description;
    QDateTime created_at;
    QDateTime updated_at;
};

class Database : public QObject {
    Q_OBJECT

public:
    explicit Database(QObject *parent = nullptr);
    ~Database();

    bool initialize();
    bool createTables();

    // CRUD Operations
    bool addProduct(const QString &product_id, const QString &name, const QString &description);
    bool addSystem(const QString &system_id, const QString &name, const QString &description);
    bool addComponent(const QString &component_id, const QString &name, const QString &description);
    bool addPart(const QString &part_id, const QString &name, const QString &description);

    QList<Product> getProducts();
    QList<System> getSystems();
    QList<Component> getComponents();
    QList<Part> getParts();

    bool updateProduct(const QString &product_id, const QString &name, const QString &description);
    bool updateSystem(const QString &system_id, const QString &name, const QString &description);
    bool updateComponent(const QString &component_id, const QString &name, const QString &description);
    bool updatePart(const QString &part_id, const QString &name, const QString &description);

    bool deleteProduct(const QString &product_id);
    bool deleteSystem(const QString &system_id);
    bool deleteComponent(const QString &component_id);
    bool deletePart(const QString &part_id);

private:
    QSqlDatabase db;
};

#endif // DATABASE_H